package com.ruoyi.web.controller.qiushi.equipment;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.qiushi.domain.equipment.QiushiWarning;
import com.ruoyi.qiushi.service.equipment.IQiushiWarningService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预警Controller
 *
 * @author ruoyi
 * @date 2024-01-16
 */
@RestController
@RequestMapping("/qiushi/equipment/qiushiwarning")
public class QiushiWarningController extends BaseController {
    @Autowired
    private IQiushiWarningService qiushiWarningService;

    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushiwarning:handleSend')")
    @GetMapping("/handleSend")
    public int handleSend(QiushiWarning qiushiWarning) {
        return qiushiWarningService.handleSend(qiushiWarning);
    }

    /**
     * 查询预警列表
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushiwarning:list')")
    @GetMapping("/list")
    public TableDataInfo list(QiushiWarning qiushiWarning) {
        startPage();
        List<QiushiWarning> list = qiushiWarningService.selectQiushiWarningList(qiushiWarning);
        return getDataTable(list);
    }

    /**
     * 导出预警列表
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushiwarning:export')")
    @Log(title = "预警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QiushiWarning qiushiWarning) {
        List<QiushiWarning> list = qiushiWarningService.selectQiushiWarningList(qiushiWarning);
        ExcelUtil<QiushiWarning> util = new ExcelUtil<QiushiWarning>(QiushiWarning.class);
        util.exportExcel(response, list, "预警数据");
    }

    /**
     * 获取预警详细信息
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushiwarning:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(qiushiWarningService.selectQiushiWarningById(id));
    }

    /**
     * 新增预警
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushiwarning:add')")
    @Log(title = "预警", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QiushiWarning qiushiWarning) {
        qiushiWarning.setUpdateTime(new Date());
        return toAjax(qiushiWarningService.insertQiushiWarning(qiushiWarning));
    }

    /**
     * 修改预警
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushiwarning:edit')")
    @Log(title = "预警", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QiushiWarning qiushiWarning) {
        return toAjax(qiushiWarningService.updateQiushiWarning(qiushiWarning));
    }

    /**
     * 删除预警
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushiwarning:remove')")
    @Log(title = "预警", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(qiushiWarningService.deleteQiushiWarningById(id));
    }
}
